<div class="box_right">
	<h1>订单列表</h1>
	<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
	  <ul class="layui-tab-title">
	    <li <?php if (!isset($order_no))echo 'class="layui-this"';?>>批量订单查询</li>
	    <li <?php if (isset($order_no))echo 'class="layui-this"';?>>按订单号查询</li>
	  </ul>
	  <div class="layui-tab-content" style="height: 100px;">
	    <div class="layui-tab-item <?php if (!isset($order_no)){echo "layui-show";}?>">
	    	<form class="layui-form" action="<?php echo base_url().'gasstation/order/index'?>" method="get">
			<div class="layui-form-item">
			  <div class="layui-inline">
			    <label class="layui-form-label" style="width: 110px;">交易时间</label>
			    <div class="layui-input-inline" style="width: 200px;">
			    	<input name="date1" type="text" class="layui-input" id="test5" placeholder="年-月-日 时:分:秒" value="<?php if (isset($date1))echo $date1;?>">
			    </div>
			    <div class="layui-form-mid">到</div>
			    <div class="layui-input-inline" style="width: 200px;">
			    	<input name="date2" type="text" class="layui-input" id="test6" placeholder="年-月-日 时:分:秒" value="<?php if (isset($date2))echo $date2;?>">
			    </div>
			    <p class="say">单次查询日期的最长跨度为31天</p>
			  </div>
			  </div>
			  <div class="layui-form-item">
			    <div class="layui-input-block">
			      <button class="btn_tj" type="submit">查询</button>
			    </div>
			  </div>
			</form>
	    </div>
	    <div class="layui-tab-item <?php if (isset($order_no)){echo "layui-show";}?>">
	    	<form class="layui-form" action="<?php echo base_url().'gasstation/order/index'?>" method="get">
			  <div class="layui-form-item">
			  <div class="layui-inline">
			    <label class="layui-form-label" style="width: 110px;">订单编号</label>
			    <div class="layui-input-inline" style="width: 200px;">
			    	<input type="text" class="layui-input" name="order_no" value="<?php if (isset($order_no)) echo $order_no;?>">
			    </div>
			  </div>
			  </div>
			  <div class="layui-form-item">
			    <div class="layui-input-block">
			      <button class="btn_tj" type="submit">查询</button>
			    </div>
			  </div>
			</form>
	    </div>
	  </div>
	  <div class="order_list" style="padding: 10px;margin-top: 15px;">
	  	<div class="layui-row">
	  		<div class="layui-col-xs4">
	  			<h2 class="order_list_h">订单列表</h2>
	  		</div>
	  	</div>
	  		
		<table class="layui-table" lay-skin="line">
		  <thead>
		    <tr>
		      <th>会员</th>
			  <th>订单编号</th>
			  <th>油号</th>
			  <th>油枪</th>
			  <th>加油量</th>
			  <th>支付方式</th>
			  <th>订单状态</th>
			  <th>订单总额</th>
			  <th>下单时间</th>
			  <th>操作</th>
		    </tr> 
		  </thead>
		  <tbody>
		    <?php if (isset($result)&&count($result)>0){
					foreach ($result as $app){
			?>
			<tr>
				<td><?php echo $app->card_name;?></td>
				<td><?php echo $app->order_no;?></td>
				<td><?php echo $app->glmodel_name;?></td>
				<td><?php echo $app->oilgun_name;?></td>
				<td><?php echo $app->oil_liters;?></td>
				<td><?php
                    if(!empty($app->from_third)){
						echo '第三方平台支付';
					}elseif($app->payment_id == 2){
                        echo "支付宝支付";
                    }elseif($app->payment_id == 3){
                    	echo "微信公众号支付";
                    }elseif($app->payment_id == 6){
                    	echo "支付宝APP支付";
					}elseif($app->payment_id == 7){
                    	echo "微信APP支付";
					}elseif($app->payment_id == 8){
                    	echo "钱包支付";
					}elseif($app->payment_id == 9){
						echo "小程序支付";
					}
					?>
				</td>
				<td><?php
					if($app->payment_status == 1&&$app->status==7){
						echo '已退款';
					}elseif($app->payment_status == 0){
						echo "未支付";
					}elseif($app->payment_status == 1){
						echo "已支付";
					}elseif($app->payment_status == 2){
						echo "已取消";
					}
					?>
				</td>
				<td><?php echo $app->order_price;?></td>
				<td><?php echo $app->create_time;?></td>
				<td>
				<?php if (in_array('gasstation/order/look_order', $_SESSION['GASSTATION_ACL_ARR'])){?>
					<a class="btn btn-sm btn-info" href="<?php echo base_url().'gasstation/order/look_order/'.$app->id;?>"><i class="icon-edit"></i>详细</a>
				<?php }?>
					<a href="javascript:void(0)" onclick="printmodal('<?php echo $app->id;?>')" data-toggle="modal" class="btn btn-sm btn-info"><i class="icon-play"></i>打印</a>
				<?php if (in_array('gasstation/order/cancel_order', $_SESSION['GASSTATION_ACL_ARR'])&&$app->payment_status == 0){?>
					<a href="javascript:void(0)" onclick="cancelmodal('<?php echo $app->id;?>')" data-toggle="modal" class="btn btn-danger btn-sm"><i class="icon-trash"></i>取消</a>
				<?php }?>
				</td>
			</tr>
				<?php }
			}else{?>
			<tr>
				<td colspan="15">无数据</td>
			</tr>
			<?php }?>
		  </tbody>
		</table>
	  </div>
	  <div class="col-sm-12">
		<div class="modal-footer no-margin-top">
			<div class="pull-left record">
				共<?php echo $count;?>条记录
				</div>
            	<?php if (isset($page))echo $page;?>
		</div>
	  </div>
	</div>   
</div>
<div id="cancelModal" class="modal fade" role="dialog" aria-hidden="true">
	<div class="modal-dialog" style="width: 300px">
		<div class="modal-content">
			<div class="modal-header">
			  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
			  <h3>提示信息</h3>
			</div>
			<div class="modal-body">
			  <p>取消订单后将无法恢复，确定要取消所选订单吗？</p>
			</div>
			<div class="modal-footer">
			  <input type="hidden" id="cancel_order_id" value="">
			  <a id="cancelbtn" href="#" class="btn btn-danger">确定</a>
			  <a href="#" class="btn btn-info" data-dismiss="modal" aria-hidden="true">取消</a>
			</div>
		</div>
	</div>
</div>
<script>
//Demo
layui.use(['form','element','laydate'], function(){
  var form = layui.form,
  	element = layui.element,
  	laydate = layui.laydate;

  //时间选择器
  laydate.render({
    elem: '#test5'
    ,type: 'datetime'
  });
    //时间选择器
  laydate.render({
    elem: '#test6'
    ,type: 'datetime'
  }); 
  
  //监听提交
  form.on('submit(formDemo)', function(data){
    layer.msg(JSON.stringify(data.field));
    return false;
  });
});
</script>
<script type="text/javascript">
function cancelmodal(id){
	$("#cancel_order_id").val(id);
    $('#cancelModal').modal('show');
}
function printmodal(id) {
	showLoading('打印小票中...');
	$.ajax( {
        url:'<?php echo site_url("gasstation/order/print_invoice")?>',
        data:{order_id:id},
        type:'post',
        cache:false,
        dataType:'json',    
        success:function(result) {
        	hideLoading();
//         	if(result.ret == '200'){
//             	if(result.data.code == '0'){
//             		window.location.reload();
//             	}else{
//             		alert("打印失败:"+result.data);
//             	}
        		
// 			}else {
// 				alert("打印失败:"+result.data);
// 			}
        },
        error : function() {
        	hideLoading();       
// 			alert("error");
        }
	});
}
$("#cancelbtn").click(function(){
	window.location.href="<?php echo base_url().'gasstation/order/cancel_order/'?>"+$("#cancel_order_id").val();
});
</script>
	